//
//  BHUserGameApplyDetailModel.swift
//  BigHealth
//
//  Created by 蔺百好 on 2021/8/24.
//

import UIKit

class BHUserGameApplyDetailModel {
    var applyId: String = ""
    var eventId: String = ""
    var fee: String = ""
    var signupTime: String = ""  // 报名赛事时间
    var signupEnd: String = ""  // 报名截止时间
    var signinStartTime: String = ""   // 签到开始时间
    var startTime: String = "" // 赛事开始时间
    var endTime: String = ""  // 赛事结束时间
    var code: String = ""  // 订单编号
    var payTime: String = ""  // 支付时间
    var teamName: String = ""  // 战队名称（团体赛）
    var shareUrl: String = "" // 邀请报名
    var enrollJson: String = ""
    
    
    var ifSignin: Int = 0 // 是否已签到
    var ifQuit: Int = 0 // 是否退赛
    var ifCaptain: Int = 0 // 是否是队长
    var eventType: Int = 0 //  1个人赛 2团体赛（团体赛没有签到）
    var reminder: Int = 0 // 未满足报名人数（0表示已满足报名人数）
    var memberNumber: Int = 0  // 战队人数（团体赛）
    
    var members: [BHGameApplyUserModel] = []
    
    var enrollJsonDic: [String:Any] = [:]
    

    
    func parseDic(_ dic: [String:Any])  {
        self.applyId = BHJsonTool.decodeStringFromDic(dic: dic, key: "id")
        self.eventId = BHJsonTool.decodeStringFromDic(dic: dic, key: "eventId")
        self.fee = BHJsonTool.decodeStringFromDic(dic: dic, key: "fee")
        self.signupTime = BHJsonTool.decodeStringFromDic(dic: dic, key: "signupTime")
        self.signupEnd = BHJsonTool.decodeStringFromDic(dic: dic, key: "signupEnd")
        self.signinStartTime = BHJsonTool.decodeStringFromDic(dic: dic, key: "signinStartTime")
        self.startTime = BHJsonTool.decodeStringFromDic(dic: dic, key: "startTime")
        self.endTime = BHJsonTool.decodeStringFromDic(dic: dic, key: "endTime")
        self.code = BHJsonTool.decodeStringFromDic(dic: dic, key: "code")
        self.payTime = BHJsonTool.decodeStringFromDic(dic: dic, key: "payTime")
        self.teamName = BHJsonTool.decodeStringFromDic(dic: dic, key: "teamName")
        self.shareUrl = BHJsonTool.decodeStringFromDic(dic: dic, key: "shareUrl")
        self.enrollJson = BHJsonTool.decodeStringFromDic(dic: dic, key: "enrollJson")

        self.enrollJsonDic = self.enrollJson.transJsonToDic()


        self.ifSignin = BHJsonTool.decodeIntFromDic(dic: dic, key: "ifSignin")
        self.ifCaptain = BHJsonTool.decodeIntFromDic(dic: dic, key: "ifCaptain")
        self.ifQuit = BHJsonTool.decodeIntFromDic(dic: dic, key: "ifQuit")
        self.eventType = BHJsonTool.decodeIntFromDic(dic: dic, key: "eventType")
        self.reminder = BHJsonTool.decodeIntFromDic(dic: dic, key: "reminder")
        self.memberNumber = BHJsonTool.decodeIntFromDic(dic: dic, key: "memberNumber")

        let array = BHJsonTool.decodeArrayFromDic(dic: dic, key: "members")
        if self.members.count != 0 {
            self.members.removeAll()
        }
        for item in array {
            if item is NSNull {
                
            }else {
                let model = BHGameApplyUserModel.init()
                model.parseDic(item as! [String:Any])
                self.members.append(model)
            }
        }
    }
}


class BHGameApplyUserModel {
    var applyid: String = ""
    var name: String = ""  //
    var phone: String = ""  // 手机号
    var custom: String = ""   // 除姓名、手机号以外自定义报名信息json字符串
    var allCustom: String = "" // 所有报名信息JSON字符串
    
    // 本地处理
    var customDic: [String:Any] = [:]
    var allCustomDic: [String:Any] = [:]
    
    func parseDic(_ dic: [String:Any])  {
        self.applyid = BHJsonTool.decodeStringFromDic(dic: dic, key: "id")
        self.name = BHJsonTool.decodeStringFromDic(dic: dic, key: "name")
        self.phone = BHJsonTool.decodeStringFromDic(dic: dic, key: "phone")
        self.custom = BHJsonTool.decodeStringFromDic(dic: dic, key: "custom")
        self.allCustom = BHJsonTool.decodeStringFromDic(dic: dic, key: "allCustom")

        self.customDic = self.custom.transJsonToDic()
        self.allCustomDic = self.allCustom.transJsonToDic()
    }
    
}
